package com.axx.android.profile.message.activity;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.axx.android.LetterApp;
import com.axx.android.R;
import com.axx.android.profile.message.model.MessageLetter;
import com.axx.android.utils.ImageLoader;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by sunjie on 2017/7/23.
 */

public class MessageLetterAdapter extends BaseQuickAdapter<MessageLetter.LetterListBean, BaseViewHolder> {


    public MessageLetterAdapter(@LayoutRes int layoutResId, @Nullable List<MessageLetter.LetterListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MessageLetter.LetterListBean item) {
        helper.setText(R.id.tv_location, item.getFromPlace() + "至" + item.getToPlace());
        if (item.getFromUser().getId().equals(LetterApp.authUser.getId())) {
            helper.setText(R.id.tv_from, "我");
            ImageLoader.loadRoundImage(item.getFromUser().getHeadPic(), (ImageView) helper.getView(R.id.iv_from_header), mContext);

            helper.setText(R.id.tv_to, item.getToUser().getNickName());
            ImageLoader.loadRoundImage(item.getToUser().getHeadPic(), (ImageView) helper.getView(R.id.iv_to_header), mContext);
        } else {
            helper.setText(R.id.tv_from, item.getFromUser().getNickName());
            ImageLoader.loadRoundImage(item.getFromUser().getHeadPic(), (ImageView) helper.getView(R.id.iv_from_header), mContext);

            helper.setText(R.id.tv_to, "我");
            ImageLoader.loadRoundImage(item.getToUser().getHeadPic(), (ImageView) helper.getView(R.id.iv_to_header), mContext);
        }

        helper.setText(R.id.tv_no, "To " + item.getTrains() + "次");
        if ("0".equals(item.getStatus())) {
            if (item.getBodyLetter() != null && item.getBodyLetter().size() != 1) {
                helper.setText(R.id.tv_status, "正在路上x" + item.getBodyLetter().size());
            } else {
                helper.setText(R.id.tv_status, "正在路上");
            }

        } else {
            if (item.getBodyLetter() != null && item.getBodyLetter().size() != 1) {
                helper.setText(R.id.tv_status, "已到达x" + item.getBodyLetter().size());
            } else {
                helper.setText(R.id.tv_status, "已到达");
            }

        }

        helper.addOnClickListener(R.id.iv_to_header);
        helper.addOnClickListener(R.id.iv_from_header);
    }
}
